package Impl;

import java.awt.Graphics;
import java.awt.Image;
import java.io.File;
import java.util.HashMap;

import javax.imageio.ImageIO;
import javax.swing.JPanel;

public class ImageBoulder extends JPanel{
	private static final long serialVersionUID = 1L;
	private static HashMap<Type, Image> images = new HashMap<Type, Image>();;
	private static boolean isFirst=true;
	private Type type;
	
	private int sizeX;
	private int sizeY;
	private Image img;
	private int positionX=0;
	private int positionY=0;
	
	public ImageBoulder(int x, int y){
		this();
		positionX = x;
		positionY = y;
	}
	
	public ImageBoulder(){
		this.sizeX = 0;
		this.sizeY = 0;
		
		if(isFirst){
			try{
				images.put(Type.Vide, ImageIO.read(new File("vide.jpg")) );
				images.put(Type.Diamant, ImageIO.read(new File("diamant.jpg")) );
				images.put(Type.Hero, ImageIO.read(new File("hero.jpg")) );
				images.put(Type.Mur, ImageIO.read(new File("mur.jpg")) );
				images.put(Type.Rocher, ImageIO.read(new File("rocher.jpg")) );
				images.put(Type.SortieFermee, ImageIO.read(new File("sortie_f.jpg"))) ;
				images.put(Type.SortieOuverte, ImageIO.read(new File("sortie_o.jpg")) );
				images.put(Type.Terre, ImageIO.read(new File("terre.jpg")) );
				//img = ImageIO.read(new File("hero.jpg"));
			}catch (Exception e) {
			}
			isFirst=false;
		}
		img = images.get(Type.Vide);
		type = Type.Vide;
	}

	public void paintComponent(Graphics g){
		g.drawImage(img, 0, 0, sizeX, sizeY, this);
		//g.drawImage(img, 0, 0, this);
	}     
	
	public void setSizeX(int x){
		sizeX = x;
	}
	
	public void setSizeY(int y){
		sizeY = y;
	}
	
	public int getSizeX(){
		return sizeX;
	}
	
	public int getSizeY(){
		return sizeY;
	}
	
	public int getPositionX(){
		return positionX;
	}
	
	public int getPositionY(){
		return positionY;
	}
	
	public void setImage(Type type){
		this.type = type;
		img = images.get(type);
	}
	
	public Type getType(){
		return type;
	}
}
